package com.example.invoicingsystem.controller;


import com.example.invoicingsystem.pojo.Sale;
import com.example.invoicingsystem.service.SaleService;
import com.example.invoicingsystem.utils.JSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@RequestMapping("sale")
@Slf4j
public class SaleController {
	@Autowired
	private SaleService productService;
	@GetMapping("selectAll")
	public JSONResult selectAll(){
		return JSONResult.ok(productService.selectAll());
	}
	@GetMapping("select")
	public JSONResult select(Sale sale){
		return JSONResult.ok(productService.select(sale));
	}
	@PostMapping("insert")
	public JSONResult insert(Sale sale){
		int id= UUID.randomUUID().hashCode();
		String userId= UUID.randomUUID().toString();
//		users.setId(id);
		return JSONResult.ok(productService.insert(sale));
	}
	@PutMapping("update")
	public JSONResult update(Sale sale){
		return JSONResult.ok(productService.update(sale));
	}
	@ResponseBody
	@DeleteMapping("delete")
	public JSONResult delete(Sale sale){
		return JSONResult.ok(productService.delete(sale));
	}
}
